<%-- 
    Document   : tree
    Created on : Oct 3, 2011, 1:16:49 PM
    Author     : Administrator
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <script type="text/javascript" src="js/jquery.js"></script>
        <script type="text/javascript" src="js/jquery.jstree.js"></script>
        <script type="text/javascript" src="js/jquery.cookie.js"></script>
        <script type="text/javascript">
            $(function(){
                $("#treedemo").jstree({
                    "json_data":{
                        "ajax":{
                            "url":"admin/categorytree",
                            "data":function(n){
                                return { id : n.attr ? n.attr("id") : "node_0" };
                            }
                        }
                    },
                    "plugins":["themes","json_data","contextmenu","crrm","cookies"]                   
                }).bind("rename.jstree",function(e, data){
                    $.get("admin/categorytree",{
                        "action":"rename",
                        "id":data.rslt.obj.attr("id"),
                        "title":data.rslt.new_name
                    },function (r) {
                        if(!r.status) {                            
                            $.jstree.rollback(data.rlbk);                           
                        }                       
                    });
                }).bind("create.jstree",function(e,data){
                    $.get("admin/categorytree",{
                        "action":"create",
                        "id":data.rslt.obj.attr("id"),
                        //                        "position" : data.rslt.position,
                        "title" : data.rslt.name,
                        "parent" : data.rslt.parent.attr("id")
                    },function (r) {
                        if(r.status) { 
                            $(data.rslt.obj).attr("id", r.id);
                        }else{
                            $.jstree.rollback(data.rlbk);                           
                        }
                    });
                }).bind("remove.jstree",function(e,data){
                    data.rslt.obj.each(function(){
                        $.ajax({
                            asyn:false,
                            url:"admin/categorytree",
                            type:"GET",
                            data:{
                                "action":"remove",
                                "id":this.id
                            },
                            success:function(r){
                                if(r.status){
                                    data.inst.refresh();
                                }
                            }
                        })
                    });
                });
            });
        </script>
    </head>
    <body>
        <h1>Hello World!</h1>
        <div id="treedemo"></div>
    </body>
</html>
